﻿using Inovout.Data.Domain;
using KuaJing.People.Domain;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace KuaJing.Organization.Domain
{

    public partial class Employee
    {
        [DataProperty("姓名", DataType.Text, null, false, 0, 99)]
        public virtual string Name
        {
            get
            {
                if (this.Person != null && this.Person.Contacts.Any(c => c.Way == ContactWay.EMail))
                {
                    return this.Person.Name;
                }
                return null;
            }
            set
            {
                if (this.Person == null)
                {
                    this.Person = new Person();
                }
                this.Person.Name = value;

            }
        }

        [DataProperty("手机", DataType.Text, null, true, 0, 99)]
        public virtual string Mobile
        {
            get
            {
                if (this.Person != null && this.Person.Contacts.Any(c => c.Way == ContactWay.Mobile))
                {
                    return this.Person.Contacts.First(c => c.Way == ContactWay.Mobile).Value;
                }
                return null;
            }
            set
            {
                if (this.Person == null)
                {
                    this.Person = new Person();
                }
                var contact = this.Person.Contacts.FirstOrDefault(c => c.Way == ContactWay.Mobile);
                if (contact == null)
                {
                    this.Person.Contacts.Add(new Contact() { Way = ContactWay.Mobile, Value = value });
                }
                else
                {
                    contact.Value = value;
                }

            }
        }
        [DataProperty("电子邮件", DataType.Text, null, false, 0, 99)]
        public virtual string EMail
        {
            get
            {
                if (this.Person != null && this.Person.Contacts.Any(c => c.Way == ContactWay.EMail))
                {
                    return this.Person.Contacts.First(c => c.Way == ContactWay.EMail).Value;
                }
                return null;
            }
            set
            {
                if (this.Person == null)
                {
                    this.Person = new Person();
                }
                var contact = this.Person.Contacts.FirstOrDefault(c => c.Way == ContactWay.EMail);
                if (contact == null)
                {
                    this.Person.Contacts.Add(new Contact() { Way = ContactWay.EMail, Value = value });
                }
                else
                {
                    contact.Value = value;
                }
            }
        }
        [DataProperty("部门", DataType.Text, null, false, null, null)]
        [Select(SelectType.ComboTree, "Name")]
        public virtual OrganizationUnit Organization
        {
            get { return this.Organizations.FirstOrDefault(); }
            set
            {
                var organization = this.Organizations.FirstOrDefault();
                if (organization != null)
                {
                    this.Organizations.Remove(organization);
                }
                this.Organizations.Add(value);
            }
        }
        [DataProperty("岗位", DataType.Text, null, true, null, null)]
        [Select(SelectType.DropDownList, "Name")]
        public virtual Position Position
        {
            get { return this.Positions.FirstOrDefault(); }
            set
            {
                var position = this.Positions.FirstOrDefault();
                if (position != null)
                {
                    this.Positions.Remove(position);
                }
                this.Positions.Add(value);
            }
        }
    }
}